import {createRouter, createWebHistory} from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: '系统首页',
      component:() => import('@/views/home/userHome.vue'),
      redirect:'/tianyanCommunity',
      children:[
        {path: '/tianyanCommunity',name:'天眼社区',component:()=>import('@/views/component/tianyanCommunity.vue')},
        {path: '/tianyanUpload',name:'天眼寻人',component:()=>import('@/views/component/tianyanUpload.vue')}
      ]
    },
    {
      path:'/login',
      name:'登录',
      component:()=>import('@/views/Login.vue'),
    },
    {
      path: '/ADMIN',
      name: '系统管理页面',
      beforeEnter(to, from, next) {
        let type = localStorage.getItem("role");
        console.log(type)
        if (type === "ADMIN") next();
        else {
          ElMessage.error('当前用户无权限访问此页面！')
          return next('/')
        }
      },
      // 跟随的边缘组件

      component: () => import('@/views/manager/Manager.vue'),
      redirect:'/ADMIN/home',
      children: [
        { path: '/ADMIN/updateInfo', component: () => import('@/views/manager/updateInfo.vue')},
        { path: '/ADMIN/password', component: () => import('@/views/manager/Password.vue')},
        { path: '/ADMIN/home', component: () => import('@/views/manager/Home.vue')},
        { path: '/ADMIN/user', component: () => import('@/views/manager/UserManager.vue')},
        {path: '/ADMIN/person',component:()=>import('@/views/manager/person.vue')},
      ]
    },
    {
      path: '/ORDINARY-USER',
      name: '普通用户界面',
      beforeEnter(to, from, next) {
        let type = localStorage.getItem("role");
        if (type === "ORDINARY-USER") next();
        else {
          ElMessage.error('当前用户无权限访问此页面！')
          return next('/')
        }
      },
      component: () => import('@/views/manager/Manager.vue'),
      redirect: '/ORDINARY-USER/home',
      children: [
        { path: '/ORDINARY-USER/person', component: () => import('@/views/manager/updateInfo.vue')},
        { path: '/ORDINARY-USER/password', component: () => import('@/views/manager/Password.vue')},
        { path: '/ORDINARY-USER/home', component: () => import('@/views/manager/Home.vue')},
        { path: '/ORDINARY-USER/admin', component: () => import('@/views/manager/UserManager.vue')},
      ]
    },
    {
      path: '/register',
      component: () => import('@/views/Register.vue')
    },
  ]
})

export default router
